#include "stdio.h"
#include "string.h"
typedef int point;
int strdevide(char s[],point front,point rear);
main(){
	int i,j,n1;
	char s[1200];
	scanf("%d",&n1);
	while(n1--){
		scanf("%s",s);
		printf("%d\n",strdevide(s,0,strlen(s)-1));
	}
}
int strdevide(char s[],point front,point rear){
	point i,j,f=front,r,t;
	int count=1,t1,t2;
	char *p,*q;
	for(j=rear;j>=front;j--){
			if(s[front]==s[j]){
				for(p=&s[front],q=&s[j];p<=q;p++,q--)
					if(*p!=*q)break;
			}
			if(p>q){
				r=j;
				t=r;
				break;
			}
	}
	for(i=front+1;r<rear;i++){
		if(i>r){
			count++;
			t=r;
		}
		for(j=rear;j>t;j--){		
				for(p=&s[i],q=&s[j];p<=q;p++,q--)
					if(*p!=*q)break;
			if(p>q){
				if(i<=r&&j>r){
					t1=strdevide(s,r+1,j);
					t2=strdevide(s,f,i-1);
					if(t1>t2){
						f=i;
						r=j;
						t=r;
						count+=t2;
						break;
					}
					else
						t=j;
				}
				else{
					f=i;
					r=j;
					break;
				}
			}
		}
	}
	return count;
}